{% extends 'AnketaBundle::layout.html.twig' %}

{#
 # @param title description of the active category
 # @param questions list of questions for the active category
 # @param answers list of answers for the active category
 # @param activeItems list of active items in menu
 # @param categoryType type of active category
 # @param subject current subject if it is relevant for the category type
 #}

{% block title %}{{ title }}{% endblock %}

{% block navigation %}
    {{ menu.hlasovanie.render(activeItems)|raw }}

{% endblock %}


{% block content %}
    <h2>{{ title }}</h2>
    <form action="#" method="post">
    {% if categoryType == 'teacher_subject' %}
        <p>{{ trans('question.index.ak_neucil') }} <em>{{ trans('question.index.uloz_a_chod') }}</em>.</p>
    {% elseif categoryType == 'subject' %}
        <p style="color: #888;">
            {{ trans('question.index.preskocte_predmet') }}
        </p>
    {% endif %}
    {% if categoryType == 'teacher_subject' or categoryType == 'subject' %}
        <p>{{ trans('question.index.chyba_v_uciteloch') }}
        <a href="{{ path('assoc_teacher_with_subject', {'subject_slug': subject.slug}) }}"
           >{{ trans('question.index.dajte_nam_vediet') }}</a>.
        </p>
    {% endif %}
    {% block submit %}
    <div class="submit">
        <input class="save" type="submit" name="save" value="{{ trans('question.index.uloz') }}" />
        <input class="next" type="submit" name="next" value="{{ trans('question.index.uloz_a_chod') }} &raquo;" />
    </div>
    {% endblock %}
    {% for question in questions %}
        <div class="question{{ question.stars ? ' stars' : '' }}">
            <h3>{{ question.question(app.request.locale) }}</h3>
            {% if question.hasDescription %}
                <div class="description">{{ question.description(app.request.locale) }}</div>
            {% endif %}

            {% if question.options | length %}
              <div class="option none">
                <label for="question_{{ question.id }}_empty">
                  <input type="radio"
                         id="question_{{ question.id }}_empty"
                         name="question[{{ question.id }}][answer]"
                         value="-1"
                      {# Warning: "x.y is not defined" or "not x.y is not none" does not work, see
                         https://github.com/fabpot/Twig/issues/319 #}
                      {% if answers[question.id] is not none %}
                        {% if not answers[question.id].hasOption %}
                          checked="checked"
                        {% endif %}
                      {% else %}
                         checked="checked"
                      {% endif %} />
              {{ trans('question.index.ziadna_odpoved') }}
              </label>
              </div>

            {% for option in question.options %}
                <div class="option">
                  <label for="question_{{ question.id }}_{{ option.id }}">
                    <input type="radio"
                           id="question_{{ question.id }}_{{ option.id }}"
                           name="question[{{ question.id }}][answer]"
                           value="{{ option.id }}"
                        {% if answers[question.id] is not none and answers[question.id].hasOption and answers[question.id].option.id == option.id %}
                            checked="checked"
                        {% endif %} />
                    {{ option.option(app.request.locale) }}
                  </label>
                </div>
            {% endfor %}
            {% endif %}

            {% if question.hasComment %}
            <div class="comment">
                <div><label for="comment_{{ question.id }}">{{ trans('question.index.komentar') }}:</label></div>
                <textarea id="comment_{{ question.id }}" class="expanding"
                          name="question[{{ question.id }}][comment]"
                    >{{ answers[question.id] is not none ? answers[question.id].comment : "" }}</textarea>
            </div>
            {% endif %}
        </div>
    {% endfor %}
    {{ block('submit') }}
    </form>
{% endblock %}
